﻿@{
    ViewBag.Title = "接口日志管理";
    Layout = "~/Views/Shared/_LayoutList.cshtml";
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>接口日志管理</title>
</head>
<body class="pear-container">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" action="">
                <div class="layui-form-item">
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">事件标题</label>
                        <div class="layui-input-inline">
                            <input type="text" name="logTitle" placeholder="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">请求方式</label>
                        <div class="layui-input-inline">
                            <input type="text" name="netRequestMethod" placeholder="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">消息</label>
                        <div class="layui-input-inline">
                            <input type="text" name="message" placeholder="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">异常信息</label>
                        <div class="layui-input-inline">
                            <input type="text" name="exception" placeholder="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">请求时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="beginTime" id="beginTime" placeholder="yyyy-MM-dd HH:mm:ss">
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">结束时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="endTime" id="beginTime" placeholder="yyyy-MM-dd HH:mm:ss">
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
                            <i class="layui-icon layui-icon-search"></i>
                            查询
                        </button>
                        <button type="reset" class="pear-btn pear-btn-md">
                            <i class="layui-icon layui-icon-refresh"></i>
                            重置
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="user-table" lay-filter="user-table"></table>
        </div>
    </div>
    <script type="text/html" id="user-bar">
        <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="Info"><i class="layui-icon layui-icon-transfer"></i></button>

    </script>
    <script>
              layui.use(['table', 'form', 'jquery','common'], function() {
                  let table = layui.table;
                  let form = layui.form;
                  let $ = layui.jquery;
                  let common = layui.common;
                  let laydate = layui.laydate;

                  let cols = [
                      [
                          {
                              title: '日志类型',
                              field: 'LogType',
                              align: 'center'
                          },
                          {
                              title: '级别',
                              field: 'LogLevel',
                              align: 'center'
                          },
                            {
                              title: '事件标题',
                              field: 'LogTitle',
                              align: 'center'
                          },
                          {
                              title: '消息',
                              field: 'Message',
                              align: 'center'
                          },
                            {
                              title: '客户端ip',
                              field: 'MachineIp',
                              align: 'center'
                          },
                              {
                              title: '请求方式',
                              field: 'NetRequestMethod',
                              align: 'center'
                          },
                          {
                              title: '请求Url',
                              field: 'NetRequestUrl',
                              align: 'center'
                          },
                          {
                              title: '是否授权',
                              field: 'NetUserIsauthenticated',
                              align: 'center'
                          },
                          {
                              title: '请求时间',
                              field: 'LogDate',
                              align: 'center',
                              templet: '#user-createTime'
                          },
                          {
                              title: '操作',
                              toolbar: '#user-bar',
                              align: 'center',
                              width: 150
                          }
                      ]
                  ]

                  table.render({
                      elem: '#user-table',
                      url: 'GetApiPageList',
                      page: true,
                      cols: cols,
                      skin: 'line',
                      toolbar: '#user-toolbar',
                       response: {
                      statusName: 'Code' //规定数据状态的字段名称，默认：code
                      , statusCode: 200 //规定成功的状态码，默认：0
                      , msgName: 'Msg' //规定状态信息的字段名称，默认：msg
                      , countName: 'recordCount' //规定数据总数的字段名称，默认：count
                      , dataName: 'ResData' //规定数据列表的字段名称，默认：data
                  },
                      defaultToolbar: [{
                          title: '刷新',
                          layEvent: 'refresh',
                          icon: 'layui-icon-refresh',
                      }, 'filter', 'print', 'exports']
                  });

               //日期时间范围
        laydate.render({
          elem: '#beginTime'
          ,type: 'datetime'
          ,range: false
        });
                //日期时间范围
        laydate.render({
          elem: '#endTime'
          ,type: 'datetime'
          ,range: false
        });

                  table.on('tool(user-table)', function(obj) {
                      if (obj.event === 'Info') {
                          window.Info(obj);
                      }
                  });
                    table.on('toolbar(user-table)', function(obj) {
                 if (obj.event === 'refresh') {
                    window.refresh();
                 }
            });

                  form.on('submit(user-query)', function(data) {
                      table.reload('user-table', {
                          where: data.field
                      })
                      return false;
                  });
                  window.Info = function(obj) {
                      console.log(obj);
                      layer.open({
                          type: 2,
                          title: '查看日志详情',
                          shade: 0.1,
                          area: [common.isModile()?'100%':'700px', common.isModile()?'100%':'600px'],
                          content: 'ApiInfo?Id='+obj.data.Id
                      });
                  }

                  window.refresh = function(param) {
                      table.reload('user-table');
                  }

              })
    </script>
</body>
</html>
